package com.huawei.statistics.jdong;

import com.huawei.statistics.pojo.video.TVPlay;
import com.huawei.statistics.pojo.video.Video;
import com.huawei.statistics.utils.HttpUtils;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created by 18573 on 2018/12/8.
 */
public class URLFecter {


    public static List<Video> URLParser (String url,int type){
        //用来接收解析的数据
        List<Video> list = new ArrayList<>();
        String entity = HttpUtils.getResultEntity(url,null,null,HttpUtils.GET);
        if(StringUtils.isNotBlank(entity)){
            list = VideoParse.getVideoList(entity,type);
            Collections.reverse(list);
            System.out.println(list.toString());
        }
        return list;
    }


    public static List<TVPlay> getAiqiyiTVPlayList(Video video){
//        if(video.getType() != 2 || video.getType() != 3)
//            return null;
        List<TVPlay> list = new ArrayList<>();
        String url = "";
        if(video.getUrl().startsWith("//")){
            url = "http:"+video.getUrl();
        }else{
            url = video.getUrl();
        }
        String entity = HttpUtils.getResultEntity(url,null,null,HttpUtils.GET);
        list = VideoParse.getTVPlayByVideo(entity,video);
        return list;
    }





    public static void main(String[] args) throws Exception {

        String url = "https://list.iqiyi.com/www/6/-------------24-2-1-iqiyi--.html";
        //String url = "http://www.iqiyi.com/a_19rrhvo5bd.html";
        String entity = HttpUtils.getResultEntity(url,null,null,HttpUtils.GET);
        System.out.println("=============="+entity);
        List<Video> list = VideoParse.getVideoList(entity,3);
        Video video = list.get(0);
        System.out.println(video);
        video.setId(20L);
        List<TVPlay> tvlist = getAiqiyiTVPlayList(video);
        System.out.println(tvlist.toString());
    }



}
